<?php
namespace Activity\Controllers\Activity;

use Activity\Controllers\BaseController;
use Activity\Models\Activity;

class IndexController extends BaseController
{
    public function initialize()
    {
        parent::initialize();
    }

    /**
     *
     */
    public function showAction()
    {
        $params = $this->dispatcher->getParams();
        if (isset($params[0]) && is_numeric($params[0])) {
            $id    = $params[0];
            $model = new Activity();
            $data  = $model->get($id);
            if ($data !== false) {
                $this->display('index/index', [
                    'title'   => $data['title'] != '' ? $data['title'] : '',
                    'content' => $data['content'] != '' ? $data['content'] : ''
                ]);
            } else {
                echo "<script>alert('活动已结束！')</script>";
            }
        }
    }

    public function getsAction()
    {
        if ($this->request->isPost()) {
            $model = new Activity();
            $ret   = $model->gets();
            if ($ret !== false) {
                return $this->json([
                    'code'     => 200,
                    'msg'      => '获取成功',
                    'response' => $ret,
                    'request'  => [
                        'controller' => $this->dispatcher->getControllerName(),
                        'action'     => $this->dispatcher->getActionName(),
                    ],
                    'other'    => []
                ]);
            }
        }
    }
}